<template>

  <div class="login-container">
    <!-- logo区域 -->
    <div class="logo">
      <img src="../assets/logo.jpg" alt="">
    </div>

    <!-- 登录表单区域 -->
    <!-- 登录的表单 -->
    <el-form :model="user" ref="userForm" label-width="0px" class="loginform_style">
      <el-form-item prop="loginname">
        <el-input v-model="user.loginname" prefix-icon="el-icon-user-solid" placeholder="输入您的用户名"></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input type="password"  v-model="user.password" prefix-icon="el-icon-s-help" placeholder="输入您的密码"></el-input>
      </el-form-item>
      <el-form-item class="btns">
        <el-button type="primary" @click="login">登录</el-button>
      </el-form-item>
    </el-form>

  </div>

</template>

<script>
    export default {
        name: "Login",
        data(){
          return{
            user:{
              loginname:'',
              password:'',
            }
          }
        },
        methods:{
          login:function(){
            this.$http.post("/user/login",this.user).then((res)=>{
              if(res.data.success){
                window.sessionStorage.setItem("user",JSON.stringify(res.data.result.user));
                window.sessionStorage.setItem("uid",JSON.stringify(res.data.result.user.id));
                window.sessionStorage.setItem("token",res.data.result.token);
                this.$router.push("/home");
                this.$message.success(res.data.message);
              }else{
                this.$message.error(res.data.message);
              }
            })
          }
        }
    }
</script>

<style scoped lang="less">
  .login-container {
    width: 450px;
    height: 314px;
    background-color: #fff;
    position: absolute;
    top: 25%;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 5px;

    .logo {
      width: 130px;
      height: 130px;
      border: 1px solid #eee;
      border-radius: 50%;
      padding: 8px;
      box-shadow: 0 0 10px #eee;
      position: absolute;
      left: 50%;
      transform: translateX(-50%) translateY(-60px);
      background-color: #fff;

      img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
        background-color: #eee;
      }
    }

    .loginform_style {
      padding: 0 20px;
      margin-top: 110px;
    }

    .btns {
      display: flex;
      justify-content: center;
    }
  }

</style>
